package lesson4.example7;

import net.bytebuddy.implementation.bind.annotation.*;

import java.lang.reflect.Method;
import java.util.concurrent.Callable;

public class Log {

    @RuntimeType
    public static Object intercept(
		@Origin Method          method, 
		@AllArguments Object[]  args, 
		@SuperCall Callable<?>  callable
    ) throws Exception {
        long start = System.currentTimeMillis();
        Object result = null;
        try {
        	result = callable.call();
            return result;
        } finally {
            System.out.println("方法名称：" + method.getName());
            
            for(int i=0;i<method.getParameterCount();i++){
            	System.out.println("第"+i+"个入参 :");
            	System.out.println("   类型：" + method.getParameterTypes()[i].getTypeName()+"，值："+args[i]);
            }
            System.out.println("返回结果：");
            System.out.println("   类型："+method.getReturnType().getName()+"，值：" + result);
            System.out.println("方法耗时：" + (System.currentTimeMillis() - start) + "ms");
        }
    }

}
